import {Post,Get,Patch,Put}  from './utilHttp'

//获取列表
function getList(reqObj,callBack){
  Get(reqObj.url,reqObj).then((res)=>{
    if(res.resCode=='0000'){
      let loadMore =res.resultCount>reqObj.iPage*reqObj.pageSize?true:false;//能否加载更多
      callBack(true,res.resultList,loadMore);//成功就返回true 对应的值 是否能加载
    }else{
      //如果不成功都掉callback
      callBack(false,res);
    }
  })
}
//日期格式化
function formatDate(nowTime){ //时间戳转化为具体的日期
  var now =new Date(nowTime)
  var year = now.getFullYear();
  var month = (now.getMonth() + 1) < 10 ? '0' + (now.getMonth() + 1) : now.getMonth() + 1;
  var date = now.getDate() < 10 ? '0' + now.getDate() : now.getDate();
  var hour = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
  var minute = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
  var second = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
  return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
}
//日期格式化 2019-10-29T08:26:39.476Z
//使用范例 formatDate1(this.dateTime[0],'yyyy-MM-dd')
function formatDate1(time){
  let date = new Date(time)
  let Str=date.getFullYear() + '/' +
  (date.getMonth() + 1) + '/' + 
  date.getDate()
  return Str
}
//毫秒转成时分秒  2019-09-01
function fmtDate(obj){
  var date = new Date(obj);
  var y = 1900 + date.getYear();
  var m = "0" + (date.getMonth() + 1);
  var d = "0" + date.getDate();
  // console.log(y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length))
        return y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length);
}
//使用范例
// getList(){
//   let _this=this;
//   //没有更多的商品
//   if(!this.loadMore){
//     return false;
//   }
//   let reqObj={
//     iPage:this.iPage,
//     pageSize:this.pageSize,
//     url:'/api/goods/queryList'
//   }
//   this.utils.getList(reqObj,(resType,resObj,loadMore)=>{
//     if(resType){
//       //成功
//       _this.list = _this.list.length>0?_this.list.concat(resObj):resObj;
//       _this.loadMore=loadMore;
//     } else {
//       Toast(resObj.resDesc);
//     }
//   })
// }
//遍历输出代码
function consoleLog(text){
  for(let ii of text){
    console.log(ii);
  }
}
export default {
  getList,
  formatDate,
  formatDate1,
  fmtDate,
  consoleLog
}